package com.redfootdev.horseskills;

import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;

public class Intelligence {

	public int horseWasFedSomething(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, ItemStack item) {
		// look up the horse and player attributes.
		Skill intelligence = hdb.getIntelligence(horse);
		// calculate the XP gain for intelligence.
		int xpGainIntelligence = 50;
		// apply XP to intelligence Skill
		if(intelligence.addXP(xpGainIntelligence)) {
			rider.sendMessage(ChatColor.AQUA + "Your Intelligence level is now " + intelligence.getLevel() + ".");
		}
		hdb.setIntelligence(horse, intelligence);
		
		return xpGainIntelligence;
	}
	public int horseWhistledFor(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider) {
		// look up the horse and player attributes.
		Skill intelligence = hdb.getIntelligence(horse);
		Skill handling = hdb.getHandling(horse, rider);
		double distance = rider.getLocation().distance(horse.getLocation());
		int xpGainIntelligence = 0;
		
		if(distance <= (10.0 + handling.getLevel()) && handling.getLevel() >= 1) {
			// calculate the XP gain for intelligence.
			xpGainIntelligence = (int)(10 + distance);
			// apply XP to intelligence Skill
			if(intelligence.addXP(xpGainIntelligence)) {
				rider.sendMessage(ChatColor.AQUA + "Your Intelligence level is now " + intelligence.getLevel() + ".");
			}
			hdb.setStrength(horse, intelligence);	
			horse.teleport(rider, TeleportCause.PLUGIN);
		}

				
		return xpGainIntelligence;
		
	}
	public String toString(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider) {

		Skill intelligence = hdb.getIntelligence(horse);


		int level = intelligence.getLevel();
		int xp = intelligence.getXP();

		
		String stats = ChatColor.AQUA + "Intelligence Level: " + level + "\nExperience: " + xp;
		return stats;
	}
	
}
